//
//  ZBHomeViewC.m
//  BaseRACDemo
//
//  Created by 庄波 on 2018/3/7.
//  Copyright © 2018年 庄波. All rights reserved.
//

#import "ZBHomeViewC.h"
#import "ZBNavigationController.h"
#import "ZBOneViewC.h"
#import "ZBTwoViewC.h"
#import "ZBThreeViewC.h"
#import "ZBFourViewC.h"

#import "ZBOneSendMessage.h"
#import "ZBResultViewC.h"
#import "ZBOwnViewC.h"


@interface ZBHomeViewC ()

/// viewModel
@property (nonatomic, readonly, strong) ZBHomePageViewModel *viewModel;

@end

@implementation ZBHomeViewC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    /// 初始化所有的子控制器
    [self setupAllChildViewController];
    
    /// set delegate
    self.tabBarController.delegate = self;
}

#pragma mark - 初始化所有的子视图控制器
- (void)setupAllChildViewController{
    NSArray *titlesArray = @[@"发送", @"结果查看", @"我的"];
    NSArray *imageNamesArray = @[@"call_nomal",
                                 @"record_nomal",
                                 @"my_nomal"];
    NSArray *selectedImageNamesArray = @[@"call_nomal",
                                         @"record_nomal",
                                         @"my_nomal"];
    
    /// 微信会话层
    UINavigationController *mainFrameNavigationController = ({
        ZBOneSendMessage *mainFrameViewController = [[ZBOneSendMessage alloc] initWithViewModel:self.viewModel.sendMessageModel];
        
        MHTabBarItemTagType tagType = MHTabBarItemTagTypeMainFrame;
        /// 配置
        [self _configViewController:mainFrameViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
        /// 添加到导航栏的栈底控制器
        [[ZBNavigationController alloc] initWithRootViewController:mainFrameViewController];
    });
    
    
    /// 通话结果界面
    UINavigationController *contactsNavigationController = ({
        ZBResultViewC *contactsViewController = [[ZBResultViewC alloc] initWithViewModel:self.viewModel.resuleViewModel];
        MHTabBarItemTagType tagType = MHTabBarItemTagTypeContacts;
        /// 配置
        [self _configViewController:contactsViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
        
        [[ZBNavigationController alloc] initWithRootViewController:contactsViewController];
    });
    
    
//    /// 发现
//    UINavigationController *discoverNavigationController = ({
//        ZBThreeViewC *discoverViewController = [[ZBThreeViewC alloc] initWithViewModel:self.viewModel.discoverViewModel];
//
//        MHTabBarItemTagType tagType = MHTabBarItemTagTypeDiscover;
//        /// 配置
//        [self _configViewController:discoverViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];
//
//        [[ZBNavigationController alloc] initWithRootViewController:discoverViewController];
//    });
    
    /// 我的
    UINavigationController *profileNavigationController = ({
        ZBOwnViewC *profileViewController = [[ZBOwnViewC alloc] initWithViewModel:self.viewModel.ownViewModel];

        MHTabBarItemTagType tagType = MHTabBarItemTagTypeDiscover;
        /// 配置
        [self _configViewController:profileViewController imageName:imageNamesArray[tagType] selectedImageName:selectedImageNamesArray[tagType] title:titlesArray[tagType] itemTag:tagType];

        [[ZBNavigationController alloc] initWithRootViewController:profileViewController];
    });
    // 添加到tabBarController的子视图
    self.tabBarController.viewControllers = @[mainFrameNavigationController, contactsNavigationController, profileNavigationController ];
    
    /// 配置栈底
    [kAppDelegate.navigationControllerStack pushNavigationController:mainFrameNavigationController];
}


#pragma mark - 配置ViewController
- (void)_configViewController:(UIViewController *)viewController imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName title:(NSString *)title itemTag:(MHTabBarItemTagType)tagType {
    
    UIImage *image = [UIImage imageNamed:imageName];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.image = image;
    viewController.tabBarItem.tag = tagType;
    
    UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] imageWithTintColor:KUIColorARGBString(@"#5EB8E9")];
    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = selectedImage;
    viewController.tabBarItem.title = title;
    
    NSDictionary *normalAttr = @{NSForegroundColorAttributeName:KUIColorARGBString(@"#929292"),
                                 NSFontAttributeName:kSetting.font_10};
    NSDictionary *selectedAttr = @{NSForegroundColorAttributeName:KUIColorARGBString(@"#5EB8E9"),
                                   NSFontAttributeName:kSetting.font_10};
    [viewController.tabBarItem setTitleTextAttributes:normalAttr forState:UIControlStateNormal];
    [viewController.tabBarItem setTitleTextAttributes:selectedAttr forState:UIControlStateSelected];
    
    [viewController.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, 0)];
    [viewController.tabBarItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
